package com.jhx.mall.dao.impl;

import com.jhx.mall.dao.BaseDao;
import com.jhx.mall.dao.DtsCateDetailDao;
import com.jhx.mall.entity.DtsCategory;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description TODO
 * @Author 李琪
 * @Date 2025/3/27 14:50
 **/
public class DtsCateDetailDaoImpl extends BaseDao implements DtsCateDetailDao {
    @Override
    public List<DtsCategory> getCateDetail() {
        List<DtsCategory> list=new ArrayList<>();
        String sql="select id,name,icon_url from dts_category where pid=0 and deleted=0";
        rs=executeQuery(sql);
        try {
            while (rs.next()) {
                DtsCategory dtsCategory = new DtsCategory();
                dtsCategory.setId(rs.getLong("id"));
                dtsCategory.setName(rs.getString("name"));
                dtsCategory.setIconUrl(rs.getString("icon_url"));
                list.add(dtsCategory);
            }
        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            super.closeAll(rs,pstmt,conn);
        }
        return list;
    }

    @Override
    public List<DtsCategory> getCateDetail2(Long id) {
        List<DtsCategory> list=new ArrayList<>();
        String sql="select id,name from dts_category where deleted=0 and pid=?";
        rs=executeQuery(sql,id);
        try {
            while (rs.next()) {
                DtsCategory dtsCategory = new DtsCategory();
                dtsCategory.setId(rs.getLong("id"));
                dtsCategory.setName(rs.getString("name"));
                list.add(dtsCategory);
            }
        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            super.closeAll(rs,pstmt,conn);
        }
        return list;
    }
}
